package com.northwest_man.refactor_tool;

import java.time.LocalTime;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class JiaBan {


    public static void main(String[] args) {
        String input = "星期二\n" +
                "09:19\n" +
                "09:30\n" +
                "00:00\n" +
                "--\n" +
                "--\n" +
                "--\n" +
                "18656075\n" +
                "郑汉荣\n" +
                "2024-04-29\n" +
                "星期一\n" +
                "09:00\n" +
                "19:45\n" +
                "00:00\n" +
                "否\n" +
                "否\n" +
                "0\n" +
                "18656075\n" +
                "郑汉荣\n" +
                "2024-04-28\n" +
                "星期日\n" +
                "09:27\n" +
                "18:51\n" +
                "00:00\n" +
                "否\n" +
                "否\n" +
                "0\n" +
                "18656075\n" +
                "郑汉荣\n" +
                "2024-04-27\n" +
                "星期六\n" +
                "00:00\n" +
                "否\n" +
                "否\n" +
                "0\n" +
                "18656075\n" +
                "郑汉荣\n" +
                "2024-04-26\n" +
                "星期五\n" +
                "19:11\n" +
                "19:11\n" +
                "00:00\n" +
                "否\n" +
                "否\n" +
                "0\n" +
                "18656075\n" +
                "郑汉荣\n" +
                "2024-04-25\n" +
                "星期四\n" +
                "09:30\n" +
                "19:03\n" +
                "00:00\n" +
                "否\n" +
                "否\n" +
                "0\n" +
                "18656075\n" +
                "郑汉荣\n" +
                "2024-04-24\n" +
                "星期三\n" +
                "09:20\n" +
                "20:43\n" +
                "00:00\n" +
                "否\n" +
                "否\n" +
                "0\n" +
                "18656075\n" +
                "郑汉荣\n" +
                "2024-04-23\n" +
                "星期二\n" +
                "09:23\n" +
                "21:30\n" +
                "00:00\n" +
                "否\n" +
                "否\n" +
                "0\n" +
                "18656075\n" +
                "郑汉荣\n" +
                "2024-04-22\n" +
                "星期一\n" +
                "09:23\n" +
                "19:39\n" +
                "00:00\n" +
                "否\n" +
                "否\n" +
                "0\n" +
                "18656075\n" +
                "郑汉荣\n" +
                "2024-04-21\n" +
                "星期日\n" +
                "00:00\n" +
                "否\n" +
                "否\n" +
                "0\n" +
                "18656075\n" +
                "郑汉荣\n" +
                "2024-04-20\n" +
                "星期六\n" +
                "00:00\n" +
                "否\n" +
                "否\n" +
                "0\n" +
                "18656075\n" +
                "郑汉荣\n" +
                "2024-04-19\n" +
                "星期五\n" +
                "09:11\n" +
                "18:48\n" +
                "00:00\n" +
                "否\n" +
                "否\n" +
                "0\n" +
                "18656075\n" +
                "郑汉荣\n" +
                "2024-04-18\n" +
                "星期四\n" +
                "09:14\n" +
                "19:10\n" +
                "00:00\n" +
                "否\n" +
                "否\n" +
                "0\n" +
                "18656075\n" +
                "郑汉荣\n" +
                "2024-04-17\n" +
                "星期三\n" +
                "09:28\n" +
                "20:49\n" +
                "00:00\n" +
                "否\n" +
                "否\n" +
                "0\n" +
                "18656075\n" +
                "郑汉荣\n" +
                "2024-04-16\n" +
                "星期二\n" +
                "09:22\n" +
                "21:09\n" +
                "00:00\n" +
                "否\n" +
                "否\n" +
                "0\n" +
                "18656075\n" +
                "郑汉荣\n" +
                "2024-04-15\n" +
                "星期一\n" +
                "09:15\n" +
                "20:47\n" +
                "00:00\n" +
                "否\n" +
                "否\n" +
                "0\n" +
                "18656075\n" +
                "郑汉荣\n" +
                "2024-04-14\n" +
                "星期日\n" +
                "00:00\n" +
                "否\n" +
                "否\n" +
                "0\n" +
                "18656075\n" +
                "郑汉荣\n" +
                "2024-04-13\n" +
                "星期六\n" +
                "00:00\n" +
                "否\n" +
                "否\n" +
                "0\n" +
                "18656075\n" +
                "郑汉荣\n" +
                "2024-04-12\n" +
                "星期五\n" +
                "09:16\n" +
                "19:01\n" +
                "00:00\n" +
                "否\n" +
                "否\n" +
                "0\n" +
                "18656075\n" +
                "郑汉荣\n" +
                "2024-04-11\n" +
                "星期四\n" +
                "09:22\n" +
                "21:29\n" +
                "00:00\n" +
                "否\n" +
                "否\n" +
                "0\n" +
                "18656075\n" +
                "郑汉荣\n" +
                "2024-04-10\n" +
                "星期三\n" +
                "09:18\n" +
                "21:19\n" +
                "00:00\n" +
                "否\n" +
                "否\n" +
                "0\n" +
                "18656075\n" +
                "郑汉荣\n" +
                "2024-04-09\n" +
                "星期二\n" +
                "09:23\n" +
                "20:42\n" +
                "00:00\n" +
                "否\n" +
                "否\n" +
                "0\n" +
                "18656075\n" +
                "郑汉荣\n" +
                "2024-04-08\n" +
                "星期一\n" +
                "09:21\n" +
                "22:43\n" +
                "00:00\n" +
                "否\n" +
                "否\n" +
                "0\n" +
                "18656075\n" +
                "郑汉荣\n" +
                "2024-04-07\n" +
                "星期日\n" +
                "09:25\n" +
                "21:12\n" +
                "00:00\n" +
                "否\n" +
                "否\n" +
                "0\n" +
                "18656075\n" +
                "郑汉荣\n" +
                "2024-04-06\n" +
                "星期六\n" +
                "00:00\n" +
                "否\n" +
                "否\n" +
                "0\n" +
                "18656075\n" +
                "郑汉荣\n" +
                "2024-04-05\n" +
                "星期五\n" +
                "00:00\n" +
                "否\n" +
                "否\n" +
                "0\n" +
                "18656075\n" +
                "郑汉荣\n" +
                "2024-04-04\n" +
                "星期四\n" +
                "00:00\n" +
                "否\n" +
                "否\n" +
                "0\n" +
                "18656075\n" +
                "郑汉荣\n" +
                "2024-04-03\n" +
                "星期三\n" +
                "09:27\n" +
                "12:55\n" +
                "00:00\n" +
                "否\n" +
                "是\n" +
                "0\n" +
                "18656075\n" +
                "郑汉荣\n" +
                "2024-04-02\n" +
                "星期二\n" +
                "09:27\n" +
                "21:01\n" +
                "00:00\n" +
                "否\n" +
                "否\n" +
                "0\n" +
                "18656075\n" +
                "郑汉荣\n" +
                "2024-04-01\n" +
                "星期一\n" +
                "09:28\n" +
                "20:48"; // 输入字符串，包含时间子串和无关字符子串
        String officialOffTime = "20:30"; // 公司规定的下班时间

        int totalOvertimeMinutes = calculateOvertimeMinutes(officialOffTime, input);
        System.out.println("Total Overtime Minutes: " + totalOvertimeMinutes);
    }

    private static int calculateOvertimeMinutes(String officialOffTime, String input) {
        int totalOvertimeMinutes = 0;
        LocalTime officialOffLocalTime = LocalTime.parse(officialOffTime);

        Pattern pattern = Pattern.compile("\\b\\d{2}:\\d{2}\\b"); // 正则表达式匹配 "hh:mm" 格式的时间子串
        Matcher matcher = pattern.matcher(input);

        while (matcher.find()) {
            String timeStr = matcher.group();
            LocalTime time = LocalTime.parse(timeStr);

            if (time.isAfter(officialOffLocalTime)) {
                int overtimeMinutes = time.getHour() * 60 + time.getMinute() - officialOffLocalTime.getHour() * 60 - officialOffLocalTime.getMinute();
                totalOvertimeMinutes += overtimeMinutes;
            }
        }

        return totalOvertimeMinutes;
    }


}
